import { EventEmitter } from 'stream';
import * as vscode from 'vscode';

export class ConfigurationService extends EventEmitter {
    public configuration: vscode.WorkspaceConfiguration;

    constructor() {
        super();
        this.configuration = vscode.workspace.getConfiguration('server');

        vscode.workspace.onDidChangeConfiguration((e) => this.doEmit(e));
    }

    doEmit(e: any) {
        this.configuration = vscode.workspace.getConfiguration('server');
        this.emit('update', this.configuration);
    }

    update(section: string, value: string[]) {
        this.configuration.update(section, value);
    }

    get(section: string) {
        return this.configuration.get(section);
    }
}

const configurationService = new ConfigurationService();

export default configurationService;
